#region File Header
//----------------------------------------------------------------
// Copyright (C) 2002 Stefan Kyntchev
// All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR 
// FITNESS FOR A PARTICULAR PURPOSE.
//----------------------------------------------------------------
#endregion File Header

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Security;
using System.Security.Principal;
using System.Threading;
using AirWeb.ApplicationTools.Common;


namespace FlashBack.Web
{
	/// <summary>
	/// Summary description for ApplicationError.
	/// </summary>
	public partial class ApplicationError : PageBase
	{

		protected Exception LastException = null;
	
		public ApplicationError()
		{
			Page.Init += new System.EventHandler(Page_Init);
		}

		protected void Page_Load(object sender, System.EventArgs e)
		{
			Object o = Application["LastError"]; 
			if(o is Exception)
			{
				LastException = (Exception)o;

				// Fin the "lowest" exception and log it.
				while(LastException.InnerException != null)
					LastException = LastException.InnerException;
			}

			ShowErrorDetails();
			CommonHelper.LogException(LastException);
		}

		private void ShowErrorDetails()
		{
			if(LastException is System.UnauthorizedAccessException)
			{
				string ErrorText = "Security exception occurred! <br>";
				ErrorText += LastException.Message + "<br>";
				ErrorText += "Make sure that the user " + WindowsIdentity.GetCurrent().Name + " has READ and WRITE/CREATE rights to the path above.";
				ErrorDescription.Text = ErrorText;
			}
			else if( LastException != null)
			{
				ErrorDescription.Text = LastException.Message;
			}
		}

		protected void Page_Init(object sender, EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
		}

		#region Web Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion
	}
}
